package com.demo.day716;

/**
 * @Auther: MFM
 * @Date: 2021/7/16 - 07 - 16 - 22:11
 * @version: 1.0
 */

public class Work1 {
    static void changeNum(String number) {
        String characterStr = "零壹贰叁肆伍陆柒捌玖";
        String unitStr = "圆拾佰仟万拾佰仟亿拾佰仟";
        String[] parts = number.split("\\.");
        String result = "";
        for (int i = 0; i < parts[0].length(); i++) {
            char ch = parts[0].charAt(i);
            int index = ch - '0';
            result = result.concat(String.valueOf(characterStr.charAt(index)));
            index = parts[0].length()-1-i;
            result = result.concat(String.valueOf(unitStr.charAt(index)));
        }
        if (parts.length>1){
            for (int i = 0; i < parts[1].length(); i++) {
                if (i==0){
                    result = result.concat("点");
                }
                char ch = parts[1].charAt(i);
                int index = ch - '0';
                result = result.concat(String.valueOf(characterStr.charAt(index)));
            }
        }

        System.out.println(number+"结果为"+result);
    }

    /*
        1.创建一个字符串形式的浮点数
        2.大写数字的基础字符串
        3.先确定小数点前有几位，小数点后有几位
        4.小数点前根据不同位置来确定单位是万仟佰拾
        5.小数点后直接concat连接
    */


    public static void main(String[] args) throws Exception {
        String num = "765.67";
        double num1 = Double.parseDouble(num);

        char[] basicChar = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '拾', '佰', '仟', '万','拾','佰','仟','亿','拾','佰','仟'};

        int length = num.length();

        //小数点前的几位数字
        int before = (int) num1 % 1000000000;
        int lengthB = String.valueOf(before).length();

        //新数组
        String NewNum = "";

        for (int i = 0; i < length; i++) {
            char Nch;
            char ch = num.charAt(i);
            if (String.valueOf(ch).equals(".")) {
                Nch = '点';
            } else {
                Nch = basicChar[ch - '0'];
            }
            NewNum = NewNum.concat(String.valueOf(Nch));
        }

        char[] chars = NewNum.toCharArray();

        for (int i = 0; i < lengthB; i++) {
            if (i == lengthB - 1) {
                break;
            }
            String Before = new String(chars, 0, i * 2 + 1);
            String After = new String(chars, i * 2 + 1, chars.length - (i * 2) - 1);
            NewNum = Before.concat(String.valueOf(basicChar[8 + lengthB - i])).concat(After);
            chars = NewNum.toCharArray();
        }
        System.out.println(NewNum);
        changeNum(num);
    }
}
